<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>clampNumber</title>
</head>

<body>
    <div>打开浏览器控制台查看结果</div>
    <script>
        const clampNumber = (num, a, b) =>
            Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
        console.log(clampNumber(2, 3, 5)); // 3
        console.log(clampNumber(1, -1, -5)); // -1
    </script>
</body>

</html>